let now = new Date()
let nowDayOfWeek = now.getDay()
let nowDay = now.getDate()
let nowMonth = now.getMonth()
let nowYear = now.getFullYear()
// 格式化日期
let formatDate = function(date) {
  const year = date.getFullYear()
  let month = date.getMonth() + 1
  let day = date.getDate()
  if ( month < 10 ) {
    month = `0${month}`
  }
  if ( day < 10 ) {
    day = `0${day}`
  }
  return (`${year}.${month}.${day}`)
}
  // 将日期与周几对应
  function getFormatWeek(date) {
    let thisDay = new Date(date).getDay()
    let weekDay = ['周日','周一','周二','周三','周四','周五','周六']
    return [date, weekDay[thisDay]]
  }
  // 计算本周起始日期
  function getWeek() {
    let startTime = formatDate(new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 1))
    let endTime = formatDate(new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 7))
    return [startTime, endTime]
  }
  // 计算本月起始日期
  function getMonth() {
    let startTime = formatDate(new Date(nowYear, nowMonth, 1))
    let endTime = formatDate(new Date(nowYear, nowMonth + 1, 0))
    // 下月第0天表示本月第一天
    return [startTime, endTime]
  }
module.exports = {formatDate, getFormatWeek, getWeek, getMonth}
